%GIANNOPOULOS MENELAOS
%AEM:604


%MEROS1

%ORTHOGWNIOI PINAKES
 clear all;clc;



%orthogwnia dianysmata
%Askhsh 1
a=[2 1 1]';

b=[1 -1 -1]

b*a

% to dianusma b den einai monadiko. px [2 1 -5]

%Askhsh 2
%mporoume na prosthesoume allo ena dianusma wste to sunolo na parameinei
%orthogwnio

 a = [2 1 1]';
 
 b=b';
 c = cross(a,b);
 figure(1); 
 clf;
 drawVector([a b c],{'a','b','c'});  %to 'r.' deixnei mono kokkines teleies. to idio kai me 'rs'
 view(-160, 7)
pause;
 
 %orthokanonika sunola kai orthokanonikoi pinakes
 %Askhsh 3
 
 
 A = [a b c];
 X = sampleUnitSphere(3,200); 
 AX = A*X;
 figure(1);
 clf;
 hold on;
 plot3( X(1,:), X(2,:), X(3,:),'b.');
 view(-60,10)
 plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
 drawVector(A,'r.'); % to idio, deixnei mono tis koukides
 hold off; 
 axis square equal; 
 grid on;
 
 pause;
 
 % Ti shmasia exoun oi sthles tou pinaka?
 %ti mporeite na peite gia thn norma 2 tou pinaka?
 
 %Orthomonadiaioi pinakes
 %Askhsh 4
 B = [a b c];
 C = diag([1/norm(a) 1/norm(b) 1/norm(c)]);
 A = B*C;
 
 
 
 AX=A*X;;
 figure(1);
 clf
 hold on;
 plot3( X(1,:), X(2,:), X(3,:),'b.');
 view(-60,10)
 plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
 hold off; 
 axis square equal; 
 grid on;
 
 pause;
 AX=A*B*X;
 figure(1);
 clf
 hold on;
 plot3( X(1,:), X(2,:), X(3,:),'b.');
 view(-60,10)
 plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
 hold off; 
 axis square equal; 
 grid on;
 
 pause;
 
 AX=A*A*B*X;
 figure(1);
 clf
 hold on;
 plot3( X(1,:), X(2,:), X(3,:),'b.');
 view(-60,10)
 plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
 hold off; 
 axis square equal; 
 grid on;
 
 pause;
 
 AX=A*A*A*B*X;
 figure(1);
 clf
 hold on;
 plot3( X(1,:), X(2,:), X(3,:),'b.');
 view(-60,10)
 plot3(AX(1,:),AX(2,:),AX(3,:),'g.');
 hold off; 
 axis square equal; 
 grid on;
 
 pause;
 %ti mporeite na peite gia tis idiothtes tou A
 
 %Askhsh 5
 A=[1 -1;
     1 1];
 %Anaparathste tis sthles se kanonikopoihmenh vash.Mporeite na vreite ton
 %antistrofo tou A mono apo to sxhma?Orthogwnopoihste ton A kai prostheste
 %tis orthogwnies sthles sto sxhma. Poios einai o antistrofos tou A twra?
 
 
 
 
 %NORMES PINAKWN
 
 %Askhsh 1
 
 B=[1 3;
     1 1];
 C=reshape(1:4,2,2);
 
 %Askhsh 2
 
 %Askhsh 3
 
 %Askhsh 4
 
 %Askhsh 5
 
 %Askhsh 6
 
 %PROVOLES
 
 %Askhsh 1
 
  
 %Askhsh 2
 
 %Askhsh 3
 
 %Askhsh 4
 
 
 %ANTISTROFOS PINAKAS
 
 A = [ 1 1; -2 2 ];
 
 e1 = [1;0];
 e2 = [0;1]; 
 figure(1);
 clf;
 hold on;
 drawVector(A, {'a','b'});
 drawVector([e1 e2], 'gs', {'e_1', 'e_2'});
 %drawVector(inv(A),{'c','d'});
 hold off;
 
 
pause;
 
 %Askhsh 1
 
 
 %Askhsh 2
 
 invA=inv(A)
 P1 = A*diag(invA(:,1))% Find the *oblique projections* of e_1 
 figure(1); hold on; 
 % Plot the projections 
 drawVector(P1, 'rd');
 drawLine([e1 P1(:,1)]); % Indicate the projection lines for e_1 
 drawLine([e1 P1(:,2)]);
 hold off
 
 pause;
 %PARAGONTOPOIHSH LU
 
 %Askhsh 1
 
  % A = [ 2 4; 3 6 ]; 
 %  b = [4 7]';
 A = [ 4 1;2 4 ]; b = [2 -2]';

  x = A\b; 
  figure(1);
  clf; hold on; 
  drawVector(A, {'a_1', 'a_2'})
  drawVector(b, 'rs', {'b'}); 
  Pb = A*diag(x); 
  drawVector(Pb, 'g+', {'x_{11}\cdot a_1', 'x_{21}\cdot a_2'});
drawLine([b Pb(:,1)]);
drawLine([b Pb(:,2)]);
hold off; 
title('Ax=b in the column space', 'FontSize', 14);
 
 
 
 
 
 
figure(2); clf; hold on; 
drawPlane(A(1,:), b(1), 'b'); 
drawPlane(A(2,:), b(2), 'g'); 
hold off title('Ax=b in the row space', 'FontSize', 14);

pause;

%Askhsh 2

A = [3 12 1; 12 0 2; 0 2 3];
b = [2.36 5.26 2.77]';
x = A\b
Pb = A*diag(x);
figure(1);clf;hold on;
drawVector(A, {'a_1','a_2','a_3'});
drawVector(b, 'rs', {'b'});
drawLine([b Pb(:,1)]);
hold off;
title('Ax=b in the column space', 'FontSize', 14);
 
figure(2); clf; hold on;
drawPlane(A(1,:), b(1), 'b');
drawPlane(A(2,:), b(2), 'g');
drawPlane(A(3,:), b(3), 'r');
plot3(x(1),x(2),x(3), 'mx', 'LineWidth', 4, 'MarkerSize', 15)
hold off title('Ax=b in the row space', 'FontSize', 14);

pause;

 %Askhsh 3
 
 A = [ 4 1 ; 0 3.5 ];
 b = [2 -3]';
 figure(3);
 clf; hold on;
 drawPlane(A(1,:), b(1), 'b');
 drawPlane(A(2,:), b(2), 'g');
 hold off title('Ax=b in the row space', 'FontSize', 14);
 figure(3);
 hold on;
plot(x(1), x(2), 'rx', 'MarkerSize', 16, 'LineWidth', 2);
hold off;

x = A\b;
figure(2);
clf; hold on; 
drawVector(A, {'a_1', 'a_2'});
drawVector(b, 'rs', {'b'}); 
Pb = A*diag(x);
drawVector(Pb, 'g+', {'x_{11}\cdot a_1', 'x_{21}\cdot a_2'});
drawLine([b Pb(:,1)]); 
drawLine([b Pb(:,2)]);
hold off;
title('Ax=b in the column space', 'FontSize', 14);



%Askhsh 4
%den yparxei backsub sto eclass

%Askhsh 5
%den yparxei slu sto eclass

%Askhsh 6
%omoiws

%Askhsh 7
%omoiws